package java基础语法练习.unsafe;

import java基础语法练习.ExampleObj;
import sun.misc.Unsafe;

import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author caihe
 * @date 2021/10/20 10:13
 */
public class UnSafeDemo {

    /**
     * 获取Unsafe实例
     */
//    private static final Unsafe unsafeno = Unsafe.getUnsafe();
   


    public static void main(String[] args) throws NoSuchFieldException {
//        long state = unsafe.objectFieldOffset(ExampleObj.class.getField("state"));
//        long state1 = unsafe.objectFieldOffset(ExampleObj.class.getField("state"));
//        long des = unsafe.objectFieldOffset(ExampleObj.class.getField("des"));
//        System.out.println(state);
//        System.out.println(state1);
//        System.out.println(des);
        ExampleObj a = new ExampleObj();
        System.out.println(ExampleObj.getStateOffset());
        System.out.println();
        
        a.setState(100);
        System.out.println(a.getState());
        a.changeValue(ExampleObj.getStateOffset(), 100, 1);
        System.out.println(a.getState());
        a.changeValue(ExampleObj.getStateOffset(), 1, 1001);
        System.out.println(a.getState());
        System.out.println();
        
        
        System.out.println(ExampleObj.getStateOffset());
        ExampleObj b = new ExampleObj();
        System.out.println(ExampleObj.getStateOffset());



    }

    
    
    


}
